#include <stdio.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/wait.h>

int main()
{
    pid_t id = fork();

    if(id == 0)
    {
        printf("I'm child, pid = %d\n", getpid());
        sleep(5);

        return 0;
    }

    int status = 0;

    while(1)
    {
        sleep(1);
        int ret = waitpid(id, &status, WNOHANG);

        if(ret == 0)
        {
            printf("子进程未结束，执行其他任务...\n");
            //执行其他任务
        }
        else if (ret > 0)
        {
            printf("wait over! pid = %d\n", ret);
            break;
        }
        else
        {
            printf("waitpid错误!\n");
            break;
        }
    }

    return 0;
}